define(['jquery'], () =>{
    class Header {
        constructor () {
            this.loadHTML().then(()=>{
                //只要涉及header的一些DOM操作就在这里写
                this.join()
                this.calcCartCount()
            })
        }
        loadHTML () {
            return new Promise((resolve,reject)=>{
                $('header').load('/html/modules/header.html',()=>{
                    resolve()
                })
                
            })
        }
        calcCartCount () {
            let count = 0
            let cart = localStorage.getItem('cart')
            if(cart) {
                cart = JSON.parse(cart)
                count = cart.reduce((num,shop)=>{
                    num += shop.count
                    return num
                },0)
            }
            $('#shopping_num').html(count)
        }
        join () {
            $('#join').on('click',()=>{
                alert('不招人了')
            })
        }
    }
    return new Header()
});